package com.mlizhi.widgets.chart;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import com.mlizhi.base.Utils;
import com.mlizhi.kingdom.R;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class ChartView4Line extends View {

	private TypedArray array4line = null;
	private TypedArray array4text = null;
	private TypedArray array4point = null;
	private TypedArray array4axis = null;
	private TypedArray array4scale = null;
	private String[] yLabel = {"20%","30%","40%","50%","60%"};
	//xLabel 与points是一一对应的,其长度必须大于1
	private String[] xLabel4pre = {};
	private String[] xLabel4post = {};
	private float[] points4pre = {};
	private float[] points4post = {};
	
	private Context context;
	private Canvas canvas;

	private float tipX;
	private float tipY;
	private boolean showFlag = false;
	public ChartView4Line(Context context) {
		super(context);
	}

	public ChartView4Line(Context context, AttributeSet attrs) {
		super(context, attrs);

		this.context = context;
		this.array4line = context.obtainStyledAttributes(attrs,
				R.styleable.ChartView4LineSeries);
		this.array4text = context.obtainStyledAttributes(attrs,
				R.styleable.ChartView4LineText);
		this.array4point = context.obtainStyledAttributes(attrs,
				R.styleable.ChartView4LinePoint);
		this.array4axis = context.obtainStyledAttributes(attrs,
				R.styleable.ChartView4LineAxis);
		this.array4scale = context.obtainStyledAttributes(attrs,
				R.styleable.ChartView4LineScale);

	}

	
	private void draw4axis(Canvas canvas) {
		
		if(array4axis != null) {
			boolean axis4antiAlias = this.array4axis.getBoolean(R.styleable.ChartView4LineAxis_axis4antiAlias, false);
			int axis4x = this.getMeasuredWidth();
			int axis4y = this.getMeasuredHeight();
			int axis4color = this.array4axis.getColor(R.styleable.ChartView4LineAxis_axis4color,Color.parseColor("#8E8E8E"));
			float axis4strokeWidth = this.array4axis.getDimension(R.styleable.ChartView4LineAxis_axis4strokeWidth, 3.0f);
			boolean arrow4x = this.array4axis.getBoolean(R.styleable.ChartView4LineAxis_arrow4x, false);
			boolean arrow4y = this.array4axis.getBoolean(R.styleable.ChartView4LineAxis_arrow4y, false);
			
			Paint paint4axis = new Paint();
			paint4axis.setStyle(Paint.Style.FILL);
			paint4axis.setAntiAlias(axis4antiAlias);
			paint4axis.setColor(axis4color);
			paint4axis.setStrokeWidth(axis4strokeWidth);
			//ground zero is (axis4x*0.1,axis4y*0.8)
			//axis for x bottom
			canvas.drawLine((axis4x*0.1f), (axis4y*0.9f), (axis4x*0.92f), (axis4y*0.9f), paint4axis);
			
			//axis for y left
			//这里用最高点是axis4y*0.05，实际参与运算的是axis4y*0.1
			canvas.drawLine((axis4x*0.1f), (axis4y*0.05f), (axis4x*0.1f), (axis4y*0.9f+10), paint4axis);
			
			//axis for y right
			//这里用最高点是axis4y*0.05，实际参与运算的是axis4y*0.1
			canvas.drawLine((axis4x*0.92f), (axis4y*0.05f), (axis4x*0.92f), (axis4y*0.9f+10f), paint4axis);
			
			
			//arrow for x
			if(arrow4x == true){
				canvas.drawLine((axis4x*0.1f-10f), (axis4y*0.1f+10f), (axis4x*0.1f), (axis4y*0.1f), paint4axis);
				canvas.drawLine((axis4x*0.1f+10f), (axis4y*0.1f+10f), (axis4x*0.1f), (axis4y*0.1f), paint4axis);
			}
			
			//arrow for y
			if(arrow4y == true){
				canvas.drawLine((axis4x*0.92f-10f), (axis4y*0.9f-10f), (axis4x*0.92f), (axis4y*0.9f), paint4axis);
				canvas.drawLine((axis4x*0.92f-10f), (axis4y*0.9f+10f), (axis4x*0.92f), (axis4y*0.9f), paint4axis);
			}
		}else{
			array4axis.recycle();
		}
//		this.array4axis.recycle();
		
	}

	private void draw4scale(Canvas canvas) {
		int axis4x = this.getMeasuredWidth();
		int axis4y = this.getMeasuredHeight();
		if(array4scale!= null) {
			boolean scale4gridx = this.array4scale.getBoolean(R.styleable.ChartView4LineScale_scale4gridx, false);
			boolean scale4gridy = this.array4scale.getBoolean(R.styleable.ChartView4LineScale_scale4gridy, false);
			boolean scale4antiAlias = this.array4scale.getBoolean(R.styleable.ChartView4LineScale_scale4antiAlias, true);
			int scale4color = this.array4scale.getColor(R.styleable.ChartView4LineScale_scale4color, Color.parseColor("#8E8E8E"));
			float scale4strokeWidth = this.array4scale.getDimension(R.styleable.ChartView4LineScale_scale4strokeWidth, 1.0f);
			boolean scale4showXLabel = this.array4scale.getBoolean(R.styleable.ChartView4LineScale_scale4showXLabel, false);
			float text4size = this.array4text.getDimension(R.styleable.ChartView4LineText_text4size, 30.0f);
//		String text4unit = this.array4text.getString(R.styleable.ChartView4Text_text4unit);
//		String text4unit = "%";
			Paint paint4scale = new Paint();
			paint4scale.setStyle(Paint.Style.FILL);
			paint4scale.setAntiAlias(scale4antiAlias);
			paint4scale.setColor(scale4color);
			paint4scale.setStrokeWidth(Utils.dip2px(context,scale4strokeWidth));
			paint4scale.setTextSize(Utils.dip2px(context, 12.0f));
			
			for(int i=0;i<yLabel.length;i++){
				//scale for y
				canvas.drawCircle(axis4x*0.1f,axis4y*0.9f-i*axis4y/(yLabel.length+1),  5, paint4scale);
//			//label for y
				canvas.drawText(yLabel[i], (axis4x*0.1f-paint4scale.measureText(yLabel[i])-8f),axis4y*0.9f-i*axis4y/(yLabel.length+1), paint4scale);
			}
			
			
			if (scale4showXLabel == true) {
				if(xLabel4pre.length>1){
					for (int i = 0; i < xLabel4pre.length; i++) {
						// scale for x
						if(xLabel4pre[i]!=null&&!"".equals(xLabel4pre[i]))
							canvas.drawCircle( (axis4x * 0.1f + i * axis4x*0.82f /(xLabel4pre.length-1)), axis4y * 0.9f, 5.0f, paint4scale);
						// label for x
						float xLabel4X = axis4x * 0.1f + i * axis4x*0.82f /(xLabel4pre.length-1)-paint4scale.measureText(xLabel4pre[i])*0.5f;
						float xLabel4Y = axis4y * 0.90f+(paint4scale.getFontMetrics().bottom-paint4scale.getFontMetrics().top);
						canvas.drawText(xLabel4pre[i], xLabel4X, xLabel4Y, paint4scale);
					}
				}
				if(xLabel4post.length>1){
					for (int i = 0; i < xLabel4post.length; i++) {
						// scale for x
						if(xLabel4post[i]!=null&&!"".equals(xLabel4post[i]))
							canvas.drawCircle( (axis4x * 0.1f + i * axis4x*0.82f /(xLabel4post.length-1)), axis4y * 0.9f, 5.0f, paint4scale);
						// label for x
						float xLabel4X = axis4x * 0.1f + i * axis4x*0.82f /(xLabel4post.length-1)-paint4scale.measureText(xLabel4post[i])*0.5f;
						float xLabel4Y = axis4y * 0.90f+(paint4scale.getFontMetrics().bottom-paint4scale.getFontMetrics().top);
						canvas.drawText(xLabel4post[i], xLabel4X, xLabel4Y, paint4scale);
					}
				}
			}
			
			
			paint4scale.setColor(Color.TRANSPARENT);
			paint4scale.setStyle(Paint.Style.STROKE);
			Path path = new Path();   
			if(scale4gridx==true){
				PathEffect effects = new DashPathEffect(new float[] { 5f, 5f, 5f, 5f}, 1f);
				paint4scale.setPathEffect(effects); 
				if(xLabel4pre.length>1){
					for(float i=1.0f;i<(float)xLabel4pre.length;){
						i+=1.0f;
						//grid for x
						canvas.drawLine((axis4x*0.1f+i*axis4x*0.82f/(xLabel4pre.length-1)),(axis4y*0.1f),(axis4x*0.1f+i*axis4x*0.82f/(xLabel4pre.length-1)),axis4y*0.9f, paint4scale);
					}
				}
				if(xLabel4post.length>1){
					for(float i=1.0f;i<(float)xLabel4post.length;){
						i+=1.0f;
						//grid for x
						canvas.drawLine((axis4x*0.1f+i*axis4x*0.82f/(xLabel4post.length-1)),(axis4y*0.1f),(axis4x*0.1f+i*axis4x*0.82f/(xLabel4post.length-1)),axis4y*0.9f, paint4scale);
					}
				}
			}
			
			
			
			if(scale4gridy==true){
				PathEffect effects = new DashPathEffect(new float[] { 5f, 5f, 5f, 5f}, 1f);
				paint4scale.setPathEffect(effects); 
				for(int i=1;i<yLabel.length;i++){
					//grid for y
					if(i%2==1){
						path.moveTo(axis4x*0.1f,axis4y*0.9f-i*axis4y/(yLabel.length+1));
						path.lineTo(axis4x*0.92f,axis4y*0.9f-i*axis4y/(yLabel.length+1));
						canvas.drawPath(path, paint4scale);
//					canvas.drawLine(axis4x*0.1f,axis4y*0.9f-i*axis4y/(yLabel.length+1),  axis4x*0.92f,axis4y*0.9f-i*axis4y/(yLabel.length+1), paint4scale);
					}
				}
			}
			
			
		}else{
			array4scale.recycle();
		}
//		this.array4scale.recycle();
	}
	private void draw4line(Canvas canvas) {
		int axis4x = this.getMeasuredWidth();
		int axis4y = this.getMeasuredHeight();
		if(array4line != null){
			
			boolean line4antiAlias = this.array4line.getBoolean(R.styleable.ChartView4LineSeries_line4antiAlias, true);
			int line4preColor = this.array4line.getColor(R.styleable.ChartView4LineSeries_line4preColor,Color.parseColor("#7AD9F7") );
			int line4postColor = this.array4line.getColor(R.styleable.ChartView4LineSeries_line4postColor,Color.parseColor("#9920BFBF") );
			float line4strokeWidth = this.array4line.getDimension(R.styleable.ChartView4LineSeries_line4strokeWidth, 1.50f);
			String line4type = this.array4line.getString(R.styleable.ChartView4LineSeries_line4style);
			Paint paint4line = new Paint();
			paint4line.setStyle(Paint.Style.STROKE);
			paint4line.setAntiAlias(line4antiAlias);
			paint4line.setColor(line4preColor);
			paint4line.setStrokeWidth(Utils.dip2px(context,line4strokeWidth));
			paint4line.setTextSize(Utils.dip2px(context,12.0f));
			Path path = new Path();
			List<float[]> validPointList4pre = new ArrayList<float[]>();
			//护理后
			if(points4pre.length>1){
//			for(int i=1;i<points4pre.length;i++){
//				if((points4pre[i-1]>=0.20f&&points4pre[i-1]<=0.6f) &&(points4pre[i]>=0.20f&&points4pre[i]<=0.6f)){
//					float startX = this.getStartPointX(axis4x)+((i-1)*this.getValidAxis4Xlength(axis4x)/(points4pre.length-1));
//					float startY = this.getYCoordinate(points4pre[i-1],axis4y);
//					float endX = this.getStartPointX(axis4x)+(i*this.getValidAxis4Xlength(axis4x)/(points4pre.length-1));
//					float endY = this.getYCoordinate(points4pre[i],axis4y);
//					float[] arr = new float[4];
//					arr[0] = startX;
//					arr[1] = startY;
//					arr[2] = endX;
//					arr[3] = endY;
//					validPointList4pre.add(arr);
//					
//				}
//				
//			}
				for(int i=0;i<points4pre.length;i++){
					if(i==0||i==points4pre.length-1){
						if(points4pre[i]<0.20f){
							points4pre[i] = 0.20f;
						}
						float pointX = this.getStartPointX(axis4x)+(i*this.getValidAxis4Xlength(axis4x)/(points4pre.length-1));
						float pointY = this.getYCoordinate(points4pre[i],axis4y);
						float[] arr = new float[2];
						arr[0] = pointX;
						arr[1] = pointY;
						validPointList4pre.add(arr);
					}else{
						if((points4pre[i]>=0.20f&&points4pre[i]<=0.6f)){
							
							float pointX = this.getStartPointX(axis4x)+(i*this.getValidAxis4Xlength(axis4x)/(points4pre.length-1));
							float pointY = this.getYCoordinate(points4pre[i],axis4y);
							float[] arr = new float[2];
							arr[0] = pointX;
							arr[1] = pointY;
							validPointList4pre.add(arr);
						}
					}
					
				}
			}
			for(int i= 0;i<validPointList4pre.size()-1;i++){
				canvas.drawLine(validPointList4pre.get(i)[0],validPointList4pre.get(i)[1],validPointList4pre.get(i+1)[0],validPointList4pre.get(i+1)[1],paint4line);
			}
//		paint4line.setStyle(Paint.Style.FILL);
//		canvas.drawCircle(0.1f*axis4x, 0.05f*axis4y, 10, paint4line);
//		canvas.drawText("护理前",0.15f*axis4x, 0.06f*axis4y, paint4line);
//		canvas.drawLine(0.06f*axis4x, 0.05f*axis4y, 0.14f*axis4x, 0.05f*axis4y, paint4line);
			//护理后设置颜色
			paint4line.setColor(line4postColor);
			paint4line.setStyle(Paint.Style.STROKE);
			List<float[]> validPointList4post = new ArrayList<float[]>();
			
//		if(points4post.length>1){
//			for(int i=1;i<points4post.length;i++){
//				if((points4post[i-1]>=0.20f&&points4post[i-1]<=0.6f) &&(points4post[i]>=0.20f&&points4post[i]<=0.6f)){
//					float startX = this.getStartPointX(axis4x)+((i-1)*this.getValidAxis4Xlength(axis4x)/(points4post.length-1));
//					float startY = this.getYCoordinate(points4post[i-1],axis4y);
//					float endX = this.getStartPointX(axis4x)+(i*this.getValidAxis4Xlength(axis4x)/(points4post.length-1));
//					float endY = this.getYCoordinate(points4post[i],axis4y);
//					float[] arr = new float[4];
//					arr[0] = startX;
//					arr[1] = startY;
//					arr[2] = endX;
//					arr[3] = endY;
//					validPointList4pre.add(arr);
////					canvas.drawLine(startX,startY,endX,endY,paint4line);
//				}
//			}
//		}
//		
//		for(float[] f:validPointList4post){
//			canvas.drawLine(f[0],f[1],f[2],f[3],paint4line);
//		}
			
			
			
//		paint4line.setStyle(Paint.Style.FILL);
//		canvas.drawCircle(0.7f*axis4x, 0.05f*axis4y, 10, paint4line);
//		canvas.drawLine(0.66f*axis4x, 0.05f*axis4y, 0.74f*axis4x, 0.05f*axis4y, paint4line);
//		canvas.drawText("护理后",0.75f*axis4x, 0.06f*axis4y, paint4line);
			
			
			if(points4post.length>1){
				for(int i=0;i<points4post.length;i++){
					if(i==0||i==points4post.length-1){
						if(points4post[i]<0.20f){
							points4post[i] = 0.20f;
						}
						float pointX = this.getStartPointX(axis4x)+(i*this.getValidAxis4Xlength(axis4x)/(points4post.length-1));
						float pointY = this.getYCoordinate(points4post[i],axis4y);
						float[] arr = new float[2];
						arr[0] = pointX;
						arr[1] = pointY;
						validPointList4post.add(arr);
					}else{
						if((points4post[i]>=0.20f&&points4post[i]<=0.6f)){
							float pointX = this.getStartPointX(axis4x)+(i*this.getValidAxis4Xlength(axis4x)/(points4post.length-1));
							float pointY = this.getYCoordinate(points4post[i],axis4y);
							float[] arr = new float[2];
							arr[0] = pointX;
							arr[1] = pointY;
							validPointList4post.add(arr);
						}
					}
					
				}
			}
			for(int i= 0;i<validPointList4post.size()-1;i++){
				canvas.drawLine(validPointList4post.get(i)[0],validPointList4post.get(i)[1],validPointList4post.get(i+1)[0],validPointList4post.get(i+1)[1],paint4line);
			}
		}else{
			array4line.recycle();
		}
		
		
		
		
	}


	private void draw4point(Canvas canvas) {
		int axis4x = this.getMeasuredWidth();
		int axis4y = this.getMeasuredHeight();
		if(array4point != null) {
			
//		int point4style = this.array4point.getInt(R.styleable.ChartView4LinePoint_point4style, 0);
			boolean point4antiAlias = this.array4point.getBoolean(R.styleable.ChartView4LinePoint_point4antiAlias, true);
			int point4preColor  = this.array4line.getColor(R.styleable.ChartView4LineSeries_line4preColor, Color.parseColor("#7AD9F7"));
			int point4postColor  = this.array4line.getColor(R.styleable.ChartView4LineSeries_line4postColor, Color.parseColor("#9920BFBF") );
			float point4strokeWidth = this.array4point.getDimension(R.styleable.ChartView4LinePoint_point4strokeWidth, 3.0f);
//		String point4type = this.array4point.getString(R.styleable.ChartView4LinePoint_point4type);
			boolean point4fill = this.array4point.getBoolean(R.styleable.ChartView4LinePoint_point4fill, true);
			Paint paint4point = new Paint();
			if(point4fill==true){
				paint4point.setStyle(Paint.Style.FILL_AND_STROKE);	
			}else{
				paint4point.setStyle(Paint.Style.STROKE);
			}
			
			paint4point.setAntiAlias(point4antiAlias);
			paint4point.setColor(point4preColor);
			paint4point.setStrokeWidth(Utils.dip2px(context,point4strokeWidth));
			
			int points4preNum = 0;
			if(points4pre.length == 1){
				points4preNum = 1;
			}else if(points4pre.length > 1){
				points4preNum = points4pre.length-1;
			}
			int points4postNum = 0;
			if(points4post.length == 1){
				points4postNum = 1;
			}else if(points4post.length > 1){
				points4postNum = points4post.length-1;
			}
			
			//为两条线描点
			for(int i=0;i<points4pre.length;i++){
				if((points4pre[i]>=0.20f&&points4pre[i]<=0.6f)){
					canvas.drawCircle(this.getStartPointX(axis4x)+(i*this.getValidAxis4Xlength(axis4x)/points4preNum), this.getYCoordinate(points4pre[i],axis4y), 5f, paint4point);
				}
			}
			paint4point.setColor(point4postColor);
			for(int i=0;i<points4post.length;i++){
				if((points4post[i]>=0.20f&&points4post[i]<=0.6f)){
					canvas.drawCircle(this.getStartPointX(axis4x)+(i*this.getValidAxis4Xlength(axis4x)/points4postNum), this.getYCoordinate(points4post[i],axis4y), 5f, paint4point);
				}
			}
			//装饰两条线上的点，为点上画白色圆环
			paint4point.setColor(Color.argb(220, 255, 255, 255));
			paint4point.setStyle(Paint.Style.STROKE);
			paint4point.setStrokeWidth(Utils.dip2px(context,0.5f));
			
			for(int i=0;i<points4pre.length;i++){
				if((points4pre[i]>=0.20f&&points4pre[i]<=0.6f)){
					canvas.drawCircle(this.getStartPointX(axis4x)+(i*this.getValidAxis4Xlength(axis4x)/points4preNum), this.getYCoordinate(points4pre[i],axis4y), 4f, paint4point);
				}
			}
			for(int i=0;i<points4post.length;i++){
				if((points4post[i]>=0.20f&&points4post[i]<=0.6f)){
					canvas.drawCircle(this.getStartPointX(axis4x)+(i*this.getValidAxis4Xlength(axis4x)/points4postNum), this.getYCoordinate(points4post[i],axis4y), 4f, paint4point);
				}
			}
		}else {
			array4point.recycle();
		}
		
		
	}
	
	private void draw4floatTip(float tipX,float tipY){
		int axis4x = this.getMeasuredWidth();
		int axis4y = this.getMeasuredHeight();
		Bitmap bitmap4pre =  BitmapFactory.decodeResource(getResources(), R.drawable.ic_tip4pre);
		Bitmap bitmap4post =  BitmapFactory.decodeResource(getResources(), R.drawable.ic_tip4post);
		Paint paint = new Paint();
		paint.setAntiAlias(true);
		paint.setTextSize(Utils.dip2px(context, 8.0f));
		//获取数值
		int index4pre = this.getXLabel4preIndexByXCoodinate(tipX, axis4x);
		int index4post = this.getXLabel4postIndexByXCoodinate(tipX, axis4x);
		float pointY4pre = 0f;
		float pointY4post = 0f;
		//获取触屏点所在的y轴坐标
		float pointYCood = this.getPointValueByYCoordinate(tipY, axis4y);
		if(points4pre.length >0){
			if(index4pre>=this.points4pre.length){
				index4pre = this.points4pre.length-1;
			}
			if(index4pre<0){
				index4pre = 0;
			}
			pointY4pre = this.points4pre[index4pre];
			//获取该数值对应在坐标系中y轴的坐标
			float tipYCood4pre = this.getYCoordinate(pointY4pre, axis4y);
//			String tipText4pre = String.valueOf(this.xLabel4pre[index4pre]);
			//获取该数值在坐标系中x轴的坐标
			float tipXCood4pre = this.getX4preCoordinate(index4pre,axis4x);
			//护理前的提示
			if(Math.abs(pointYCood-pointY4pre)<=0.02d){
				this.canvas.drawBitmap(bitmap4pre, null,new RectF(tipXCood4pre-40,tipYCood4pre-100,tipXCood4pre+40,tipYCood4pre) , paint);
				paint.setStrokeWidth(Utils.dip2px(context,10f));
				
				paint.setStyle(Paint.Style.FILL);
//				this.canvas.drawText(tipText4pre,tipXCood4pre-paint.measureText(tipText4pre)*0.5f,tipYCood4pre-60, paint);
				String tipText4numPre = ""+new BigDecimal(pointY4pre* 100).setScale(2, BigDecimal.ROUND_HALF_UP).floatValue() +"%";
				this.canvas.drawText(tipText4numPre, tipXCood4pre-paint.measureText(tipText4numPre)*0.5f,tipYCood4pre-50, paint);
			}
		}
		
		
		if(points4post.length >0){
			if(index4post>=this.points4post.length){
				index4post = this.points4post.length-1;
			}
			if(index4post<=0){
				index4post = 1;
			}
//			index4post -= 1;
			pointY4post = this.points4post[index4post];
			//获取该数值对应在坐标系中y轴的坐标
			float tipYCood4post = this.getYCoordinate(pointY4post, axis4y);
			//获取该数值在坐标系中x轴的坐标
			float tipXCood4post = this.getX4postCoordinate(index4post,axis4x);
//			String tipText4post = String.valueOf(this.xLabel4post[index4post]);
			//护理后的提示
			if(Math.abs(pointYCood-pointY4post)<=0.02d){
				this.canvas.drawBitmap(bitmap4post, null,new RectF(tipXCood4post-40,tipYCood4post-100,tipXCood4post+40,tipYCood4post) , paint);
				paint.setStrokeWidth(Utils.dip2px(context,10f));
				paint.setStyle(Paint.Style.FILL);
				
//				this.canvas.drawText(tipText4post, tipXCood4post-paint.measureText(tipText4post)*0.5f,tipYCood4post-60, paint);
				String tipText4numPost =String.valueOf(new BigDecimal(pointY4post* 100).setScale(2, BigDecimal.ROUND_HALF_UP).floatValue() +"%") ;
				this.canvas.drawText(tipText4numPost, tipXCood4post-paint.measureText(tipText4numPost)*0.5f,tipYCood4post-50, paint);
			}
		}
		
		
	}
	
	
	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		this.canvas = canvas;
		draw4axis(canvas);
		draw4scale(canvas);
		draw4line(canvas);
		draw4point(canvas);
//		if(this.showFlag == true){
//			this.draw4floatTip(tipX,tipY);
//		}
////		invalidate();  
	}

	
	
//	@Override
//	public boolean onTouchEvent(MotionEvent event) {
//		// TODO Auto-generated method stub
//		
//		tipX = event.getX();
//		tipY = event.getY();
//		if (event.getAction() == MotionEvent.ACTION_UP) {
//			this.showFlag = true;
//		}
//		invalidate();
//
//		return true;
//
//	}
//	
	
	/**
	 * 
	 * @param pointValue 该点的值 一般不超过 区间[0.20~0.60],在调用该方法时候，如果超过，劲量剔除该点
	 * @param axis4y 表示Y轴的总长度
	 * @return
	 */
	private float getYCoordinate(float pointValue,int axis4y) {
		/**
		 * 公式：axis4y*0.9-(0.8*axis4y*(4/5)/(0.60-0.20))*(pointValue-0.20) = pointYCoordinate
		 * axis4y*0.9是原点所在y轴坐标；0.8*axis4y*(4/5)是20%~60%的区间；
		 * (0.8*axis4y*(4/5)/(0.60-0.20))*(pointValue-0.20)是pointValue在该坐标系中的有坐标
		 * 公式化简得：(1.22-1.6*pointValue)*axis4y = pointYCoordinate
		 */
		
		float point4y =(1.22f-1.6f*pointValue)*axis4y;
		
		return point4y;
	}

	/**
	 * 从getYCoordinator（float pointValue,int axis4y) 反推过来的
	 * @param pointYCoordinate
	 * @param axis4y
	 * @return
	 */
	private float getPointValueByYCoordinate(float pointYCoordinate,int axis4y){
		float pointValue = 0.7625f-0.625f*(1.0f/axis4y)*pointYCoordinate;
		return pointValue;
	}
	
	/**
	 * 根据pointX去获取对应的XLabel的索引
	 * 这里要用公式：0.1f*axis4x+(0.82f*axis4x)*index/(points.length-1) = pointXCoordinate
	 * 化简得：(0.82f*index/(points.length-1)+0.1f)*axis4x = pointXCoordinate
	 * 反推过来
	 * @param pointXCoordinate
	 * @param axis4x
	 * @return
	 */
	private int getXLabel4preIndexByXCoodinate(float pointXCoordinate,int axis4x){
		float index4float = (pointXCoordinate-0.1f*axis4x)*(this.xLabel4pre.length-1)/(0.82f*axis4x);
		int index4int = new BigDecimal(index4float).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
		return index4int;
	}
	
	/**
	 * 根据pointX去获取对应的XLabel的索引
	 * 这里要用公式：0.1f*axis4x+(0.82f*axis4x)*index/(points.length-1) = pointXCoordinate
	 * 化简得：(0.82f*index/(points.length-1)+0.1f)*axis4x = pointXCoordinate
	 * 反推过来
	 * @param pointXCoordinate
	 * @param axis4x
	 * @return
	 */
	private int getXLabel4postIndexByXCoodinate(float pointXCoordinate,int axis4x){
		float index4float = (pointXCoordinate-0.1f*axis4x)*(this.xLabel4post.length-1)/(0.82f*axis4x);
		int index4int = new BigDecimal(index4float).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
		return index4int;
	}
	
	private float getX4preCoordinate(int index,int axis4x) {
		float pointXCoordinate = axis4x*0.1f+index*axis4x*0.82f/(xLabel4pre.length-1);
		return pointXCoordinate;
	}
	
	
	private float getX4postCoordinate(int index,int axis4x) {
		float pointXCoordinate = axis4x*0.1f+index*axis4x*0.82f/(xLabel4post.length-1);
		return pointXCoordinate;
	}
	
	private float getStartPointX(int axis4x){
		return axis4x*0.1f;
	}
	private float getValidAxis4Xlength(int axis4x){
		
		float validAxis4Xlength = axis4x*0.82f;
		return  validAxis4Xlength;
	}
	
	

	public String[] getxLabel4pre() {
		return xLabel4pre;
	}

	public void setxLabel4pre(String[] xLabel4pre) {
		this.xLabel4pre = xLabel4pre;
	}

	public String[] getxLabel4post() {
		return xLabel4post;
	}

	public void setxLabel4post(String[] xLabel4post) {
		this.xLabel4post = xLabel4post;
	}

	public String[] getyLabel() {
		return yLabel;
	}

	public void setyLabel(String[] yLabel) {
		this.yLabel = yLabel;
	}


	
	public float[] getPoints4pre() {
		return points4pre;
	}

	public void setPoints4pre(float[] points4pre) {
		this.points4pre = points4pre;
	}

	public float[] getPoints4post() {
		return points4post;
	}

	public void setPoints4post(float[] points4post) {
		this.points4post = points4post;
	}

	
	
	

}